package project2.util;

public class WaitingFor {
    private int remainTime;
    private final int initTime;
    private final int intervalTime;

    public WaitingFor(int initTime, int intervalTime) {
        this.initTime = initTime;
        this.intervalTime = intervalTime;
    }

    public void init() {
        remainTime = initTime;
    }

    public void runFor(Runnable runnable) {
        if (remainTime > 0) {
            remainTime -= intervalTime;
        } else {
            runnable.run();
            remainTime = initTime;
        }
    }
}
